package com.kktest.kk01.consumer;

import com.kktest.kk01.config.RabbitConfig;
import com.rabbitmq.client.Channel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @Auther: wenkang.li
 * @Date: 2021/1/22 11:18
 * @Description:
 */
@Component
public class ConsumerService {

    private static final Logger logger = LoggerFactory.getLogger(ConsumerService.class);

    @RabbitListener(queues = RabbitConfig.QUEUE_A)
    public void message(Message message, Channel channel) {
        try {
            logger.info("recevice msg...:");
            logger.info(new String(message.getBody()));
            // 消息删除
            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
        } catch (Exception e) {
            throw new RuntimeException("处理消息失败");
        }
    }
}
